package com.jiang.daily.Q3159;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jiang
 * @version 1.0
 * @date 2024/12/27 16:43
 */
class Solution {
    public int[] occurrencesOfElement(int[] nums, int[] queries, int x) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            if(nums[i] == x) {
                list.add(i);
            }
        }
        for (int i = 0; i < queries.length; i++) {
            if (queries[i] > list.size()) {
                queries[i] = -1;
            } else {
                queries[i] = list.get(queries[i] - 1);
            }
        }
        return queries;
    }
}
